/*
 * Copyright (c) 2016-2021, Hangzhou Qulian Technology Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _MD5_H_
#define _MD5_H_

#include "ql_type.h"
#include <string.h>

// -----------------------
// The MD5 structure
// -----------------------
typedef struct
{
    ql_uint32_t count[2];
    ql_uint32_t state[4];
    ql_byte_t buffer[64];
}MD5_CTX;

// -----------------------
// Internal function
// -----------------------
ql_void_t MD5Transform(ql_uint32_t state[4],ql_byte_t block[64]);
ql_void_t MD5Encode(ql_byte_t *output,ql_uint32_t *input,ql_uint32_t len);
ql_void_t MD5Decode(ql_uint32_t *output,ql_byte_t *input,ql_uint32_t len);

// -----------------------
// External function
// -----------------------
/*
Initialize MD5 object
Inputs:
    context - MD5 object.
*/
ql_void_t MD5Init(MD5_CTX *context);

/*
Hash the message, long messages can be called continuously
Inputs:
    context - MD5 object.
    input - message.
    inputlen - message length.
*/
ql_void_t MD5Update(MD5_CTX *context,ql_byte_t *input,ql_uint32_t inputlen);


/*
Filling and calculation of the last packet, and output the calculation result
Inputs:
    context - MD5 object.
Outputs:
    digest - MD5 result.
*/
ql_void_t MD5Final(MD5_CTX *context,ql_byte_t digest[16]);


#endif
